package com.lagou.edu.service.impl;

import cn.hutool.extra.mail.MailUtil;
import com.lagou.edu.service.mail.MailService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;

@Slf4j
@Service
public class MailServiceImpl implements MailService {

  private ExecutorService executorService = Executors.newSingleThreadExecutor();

  @Override
  public boolean sendMail(String email, String code) {
    try {
      executorService.submit(()->{
        MailUtil.send(email, "你要的注册验证码到了", "注册验证码："+code, false);
      });
    }catch (Exception e){
      log.error("send mail error",e);
      return false;
    }
    return true;
  }
}
